﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Elderos.Highlight.Search;
using Elderos.Utils;

namespace Elderos.Highlight
{
    [DataContract]
    public class HighlightResult
    {
        [DataMember]
        public List<Position> Positions { get; set; }

        [DataMember]
        public string Text { get; set; }

        [DataMember]
        public Token[] Tokens { get; set; }

        public IDictionary<RankingRule, object> ArticleCache { get; private set; } 

        public List<TextEntity> Entities
        {
            get { return Positions.SelectMany(x => x.EntitiesFlattened).ToList(); }
        } 

        public HighlightResult()
        {
            ArticleCache = new Dictionary<RankingRule, object>();
        }
        
        public HighlightResult(IEnumerable<Position> positions)
            : this()
        {
            Positions = new List<Position>(positions);
        }
    }
}
